<?php
$root = $_SERVER['DOCUMENT_ROOT'];
include($root . "/util/session.php"); //checks that the user is logged in
include($root . "/util/privilege_check.php");
checkPrivilege("admin");
$query = "SELECT * FROM users join user_info on users.username=user_info.login";
$result = mysqli_query($db, $query);
if (mysqli_num_rows($result) < 1) {
	$error = "No users, how did you get here?";
}
?>

<!DOCTYPE html>
<html lang="en">

<head>
	<title>User List</title>
	<link rel="stylesheet" type="text/css" href="adminStyle.css">
	<link rel="stylesheet" type="text/css" href="tableStyle.css">
</head>

<?php
include($root . "/admin/header.php");
?>

<main>

	<body>
		<li><a href="/admin/admin.php">Back</a></li>
		<table border="1px" id="users">
			<thead>
				<tr>
					<th>Username</th>
					<th>Usertype</th>
					<th>Full Name</th>
					<th>SSN</th>
					<th>Gender</th>
					<th>Phone number</th>
					<th>Email</th>
				</tr>
			</thead>
			<tbody>
				<?php //ugly php + html hybrid code that does stuff
				while ($row = mysqli_fetch_assoc($result)) { ?>
					<tr>
						<td><?php echo $row['username']; ?>
							<a href="/admin/userMod.php?login=<?php echo $row['username'] ?>">Modify</a>
							<a href="/admin/userDel.php?username=<?php echo $row['username'] ?>">Delete</a>
						</td>
						<td><?php echo $row['usertype']; ?></td>
						<td><?php echo $row['full_name']; ?></td>
						<td><?php echo $row['ssn']; ?></td>
						<td><?php echo $row['gender']; ?></td>
						<td><?php echo $row['phone']; ?></td>
						<td><?php echo $row['email']; ?></td>
						<!td>
							<?php
							//		if(!empty($row['picture'])){
							//			//}echo "<img src = /util/showImage.php?username=" . $row['username'] . " width=200 height=200 >";
							//			//echo '<img src="data:image/jpeg;base64,'.base64_encode($row['picture']).'width="200" height="200"/>';
							//			echo '<img width="100" height="100" src="data:image/jpeg;base64,'.base64_encode($row['picture']).'"/>';
							//		}
							?>
							<! /td>
					</tr>
				<?php } ?>
			</tbody>
		</table>
	</body>

</html>
</main>

<?php
include($root . "/admin/footer.php");
?>